package com.brkj.communityStudy;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.brkj.httpInterface.BaseAjaxParams;
import com.brkj.httpInterface.HttpInterface;
import com.brkj.httpInterface.NomalResult;
import com.brkj.main.R;
import com.brkj.util.MyAjaxCallBack;
import com.brkj.util.MyApplication;
import com.brkj.util.view.BaseActivity;
import com.brkj.util.view.BaseCoreActivity;
import com.brkj.util.view.WidgetAnim;
import net.tsz.afinal.FinalHttp;

/**
 * Created by colin.ding on 2014/5/30.
 */
public class QAWriteActivity extends BaseActivity{

    private EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.qa_write);
        initTitle();


        editText = (EditText) findViewById(R.id.editText);
    }

    private void initTitle() {
        setReturnBtn();
        setActivityTitle("提问题");
        setRightBtn(R.drawable.send_selector, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submit();
            }
        });
    }

    private void submit() {
        if(WidgetAnim.checkIfEmpty(this, editText)){
            return;
        }

        BaseAjaxParams params = new BaseAjaxParams();
        params.put(HttpInterface.HIF_SubmitQuestion.params.UserID, MyApplication.myUserID);
        params.put(HttpInterface.HIF_SubmitQuestion.params.Question, editText.getText().toString());

        FinalHttp fh = new FinalHttp();
        fh.post(HttpInterface.HIF_SubmitQuestion.address, params, new MyAjaxCallBack<Object>((BaseCoreActivity)this) {
            @Override
            public void onSuccess(Object o) {


                if(NomalResult.doResult(o, QAWriteActivity.this)){
                    showToast("发表成功！");
                    finish();
                }else{
                    showToast("发表失败，请重新再试！");
                }
            }
        });
    }
}
